﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace Folder_Control
{
    public class ImageButton : PictureBox
    {
        private string imageFolder = @"..\..\Folder_Control_Images\";

        public string BaseName { get; set; }

        private bool is_active;
        public bool isActive
        { 
            get
            {
                return is_active;
            }
            set
            {
                is_active = value;
                if(value)
                {
                    SetToActivePicture();
                }
                else
                {
                    SetToInactivePicture();
                }
            } 
        }

        public ImageButton(string baseName, bool active)
        {
            BaseName = baseName;
            isActive = active;
        }

        private void SetToActivePicture()
        {
            Image = Image.FromFile(imageFolder + BaseName + ".png");
        }

        private void SetToInactivePicture()
        {
            Image = Image.FromFile(imageFolder + BaseName + "_deactivated.png");
        }

        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);

            if(is_active)
                Image = Image.FromFile(imageFolder + BaseName + ".png");
        }

        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);

            if (is_active)
                Image = Image.FromFile(imageFolder + BaseName + "_down.png");
        }

        protected override void OnMouseEnter(EventArgs e)
        {
            base.OnMouseEnter(e);

            if (is_active)
                Image = Image.FromFile(imageFolder + BaseName + "_hover.png");
        }

        protected override void OnMouseLeave(EventArgs e)
        {
            base.OnMouseLeave(e);

            if (is_active)
                Image = Image.FromFile(imageFolder + BaseName + ".png");
        }
    }
}
